<?php
class threadAction extends backendAction
{
    public function _initialize() {
        parent::_initialize();
        $this->_name = 'thread';
        $this->_mod = D('thread');
    
    }

    public function _before_index() {
        $p = $this->_get('p','intval',1);
        $this->assign('p',$p);        
        //默认排序
        $this->sort = 'id';
        $this->order = 'desc';
        $this->list_relation = true;
    }

    protected function _search() {
        $map = array();
        ($time_start = $this->_request('time_start', 'trim')) && $map['addTime'][] = array('egt', strtotime($time_start));
        ($time_end = $this->_request('time_end', 'trim')) && $map['addTime'][] = array('elt', strtotime($time_end)+(24*60*60-1));
        $status = $this->_request('status', 'trim');
        if($status!=''){
            $map['status'] = $status;
        }
        ($keyword = $this->_request('keyword', 'trim')) && $map['title'] = array('like', '%'.$keyword.'%');
        $this->assign('search', array(
            'time_start' => $time_start,
            'time_end' => $time_end,         
            'status'  => $status,
            'keyword' => $keyword,
        ));
        return $map;
    }
    
    public function oppt(){
        $type = $this->_request('type');
        $this->assign('type',$type);
        if(IS_POST){
            // 多附件处理
            if(isset($_FILES['attachment'])){
                $uploadInfo = $this->_upload($_FILES['attachment'],C('thread_attr_dir'));
                if($uploadInfo['error']==0){
                    $arr = array();
                    foreach($uploadInfo['info'] as $v){
                        $t = explode('/', $v['type']);
                        $arr[$t[0]][] = '/'.C('thread_attr_dir').'/'.$v['savename'];
                    }
                    $_POST['attachment'] = serialize($arr);    
                }
            }
        }
        $this->$type();
    }

    public function _before_add()
    {

      

    }


    public function _before_edit(){
   
    }
    

    protected function _upload_init($upload,$allow_exts=null) {
        $allow_max = C('PIN_ATTR_ALLOW_SIZE'); //读取配置
        $allow_exts || $allow_exts = explode(',', C('pin_attr_allow_exts')); //读取配置
        $allow_max && $upload->maxSize = $allow_max * 1024;   //文件大小限制
        $allow_exts && $upload->allowExts = $allow_exts;  //文件类型限制
        $upload->saveRule = 'uniqid';
        $upload->autoSub = '2';
        $upload->subType = 'date';
        return $upload;
    }
  
 
}